package com.joinway.framework.extension.console;

import java.util.Date;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;

public class FileNameBuilder {

	public static String delimiter = ".";
	
	public static String buildFileName(){
		return buildFileName(FileNameStrategy.TimestampPlusUUID, null);
	}
	
	public static String buildFileName(String suffix){
		return buildFileName(FileNameStrategy.TimestampPlusUUID, suffix);
	}

	public static String buildFileName(FileNameStrategy strategy){
		return buildFileName(strategy, null);
	}
	
	public static String buildFileName(FileNameStrategy strategy, String suffix){
		String name = buildUUIDName();
		
		if(strategy == FileNameStrategy.TimestampPlusUUID){
			name = buildTimestampName() + delimiter + name;
		}else if(strategy == FileNameStrategy.Timestamp){
			name = buildTimestampName();
		}
		
		name = StringUtils.isBlank(suffix) ? name : name + "." + suffix;
		
		return name;
	}
	
	public static String buildTimestampName(){
		return DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
	}
	
	public static String buildDateName(){
		return DateFormatUtils.format(new Date(), "yyyyMMdd");
	}
	
	public static String buildUUIDName(){
		return UUID.randomUUID().toString().replaceAll("\\-", "");
	}
}

